<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        width: 500px;
        height: 500px;
        background-color: goldenrod;
    }
</style>

<body>
    <div></div>
    <button>阻止div消失</button>
    <script>
        //五秒后div消失

        var div = document.querySelector("div");
        var btn = document.querySelector("button")
        var timer = setTimeout(function() {
            div.style.display = 'none';
        }, 5000);
        btn.addEventListener('click', function() {
                clearTimeout(timer);
            })
            //间隔回调
        setInterval(function() {
            console.log("我又来了");
        }, 1000)
    </script>
</body>

</html>